package com.gl.emms.whale.ui;


import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import com.gl.emms.nio.mutual.ReplyBody;
import com.gl.emms.whale.R;
import com.gl.emms.whale.app.WhaleMonitorActivity;
import com.gl.emms.whale.db.RechargeRecordDB;
import com.gl.emms.whale.util.RechargeRecordEntity;

/**支付记录界面类
 * @author ganlinux
 *
 */
public class RechargeRecordActivity extends WhaleMonitorActivity implements OnClickListener{
	private ListView mRechargeRecordListView ;
	List<RechargeRecordEntity> recordList;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.activity_rechargerecord);
		
		initViews();
		initData();//初始化数据
		
		mRechargeRecordListView = (ListView)findViewById(R.id.rechargerecord_listView);
		
		RechargrRecordAdapter adapter = new RechargrRecordAdapter(this, recordList);
		mRechargeRecordListView.setAdapter(adapter);
		mRechargeRecordListView.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
				// TODO Auto-generated method stub

				switch (position) {
				case 0://我的信息

					break;
				case 1://我的信息
					showToask("hehe ");					
					break;
				case 2://我的信息
					//showToask("hehe ");	
					break;
				case 3://宣传片
					break;
				default:
					break;
				}

			}
		});
		
	}
	@Override
	public void initViews() {
		// TODO Auto-generated method stub
		Button titleBackBtn = (Button)findViewById(R.id.TitleBackBtn);  
		titleBackBtn.setOnClickListener(this);
	}
	public void initData() {
		recordList = new ArrayList<RechargeRecordEntity>();
		RechargeRecordDB rechargeRecordDB = new RechargeRecordDB(this);
		recordList = rechargeRecordDB.getRecord();
		if(recordList.size() == 0)
		{
			showToask("您无充值记录");
		}
		
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.TitleBackBtn:
			KeyEvent newEvent = new KeyEvent(KeyEvent.ACTION_DOWN,  
					KeyEvent.KEYCODE_BACK);
			finish();
			break;
		default:
			break;
		}
	}
	@Override
	public void onReplyReceived(final ReplyBody reply) {
		super.onReplyReceived(reply);
		if(reply.getType().equals("rechargepara_response")){
			
		}
	}
	class RechargrRecordAdapter extends BaseAdapter {
		private Context context;
		private List<RechargeRecordEntity> list;
		private LayoutInflater inflater;

		public RechargrRecordAdapter(Context context, List<RechargeRecordEntity> list) {
			// TODO Auto-generated constructor stub
			this.context = context;
			this.list = list;
			inflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ViewHoler holder;
			if (convertView == null) {
				convertView = inflater.inflate(R.layout.item_rechargerecord, null);
				holder = new ViewHoler();
				holder.bill = (TextView) convertView
						.findViewById(R.id.bill_item);
				holder.money = (TextView) convertView.findViewById(R.id.money_item);
				holder.time = (TextView) convertView
						.findViewById(R.id.time_item);
				holder.state = (TextView) convertView
						.findViewById(R.id.state_item);
				holder.user = (TextView) convertView
						.findViewById(R.id.user_item);
				holder.sync = (Button) convertView
						.findViewById(R.id.rechargerecord_btn);
				convertView.setTag(holder);
			} else {
				holder = (ViewHoler) convertView.getTag();
			}
			RechargeRecordEntity entity = list.get(position);
			holder.bill.setText(entity.getBill());
			holder.money.setText(entity.getMoney());
			holder.time.setText(entity.getTime());
			holder.state.setText(entity.getState());
			holder.user.setText(entity.getUser());
			//holder.sync.set
			return convertView;
		}

		class ViewHoler {
			TextView bill;
			TextView money;
			TextView time;
			TextView state;
			TextView user;
			Button sync;
		}
	}
	
	
}
